name: ghcr.io

on:
  push:
    branches: [ develop ]
  workflow_dispatch:

env:
  REGISTRY: ghcr.io
  UP2DATE_CONTAINER_NAME: up2date_cpp
  DPS_CONTAINER_NAME: ritms_auth
  OTT_CONTAINER_NAME: ritms_ott_exchanger

jobs:
  build:
    name: Building images
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791
        with:
          submodules: recursive
      - name: Build builder image
        run: docker build -f ./.github/Dockerfile_builder -t builder_b ./.github/.
      - name: Build artifacts
        run: docker run -i --rm -v "$(pwd):/var/up2date-cpp" builder_b

      - name: Build up2date_client image
        run: docker build -f example/Dockerfile_up2date_client . -t "${REGISTRY}/rtsoft-gmbh/${UP2DATE_CONTAINER_NAME}:latest"
      - name: Build dps_client image
        run: docker build -f example/Dockerfile_ritms_auth . -t "${REGISTRY}/rtsoft-gmbh/${DPS_CONTAINER_NAME}:latest"
      - name: Build ritms_ott_exchanger image
        run: docker build -f example/Dockerfile_ritms_ott . -t "${REGISTRY}/rtsoft-gmbh/${OTT_CONTAINER_NAME}:latest"

      - name: Login into regestry
        uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: pushing UP2DATE_CONTAINER image
        run: docker push "${REGISTRY}/rtsoft-gmbh/${UP2DATE_CONTAINER_NAME}:latest"

      - name: pushing DPS_CONTAINER image
        run: docker push "${REGISTRY}/rtsoft-gmbh/${DPS_CONTAINER_NAME}:latest"

      - name: pushing OTT_CONTAINER image
        run: docker push "${REGISTRY}/rtsoft-gmbh/${OTT_CONTAINER_NAME}:latest"
